let house_id = 0
Page({
  data: {
    dialogVisible: false,
    houseList: [],
    houseid: ''
  },

  swipeClose(ev) {
    // console.log(ev);
    const { position, instance } = ev.detail

    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })
      house_id = ev.mark.id

      // swiper-cell 滑块关闭
      instance.close()
    }

  },
  // 删除房屋
  async dialogClose() {

    const { code } = await wx.http.delete('/room/' + house_id)

    if (code !== 10000) return wx.utils.toast('删除房屋失败!')
    this.getHouseList()
  },
  onShow() {
    this.getHouseList()
  },
  // 获取列表
  async getHouseList() {
    const { code, data: houseList } = await wx.http.get('/room')
    if (code !== 10000) return wx.utils.toast()
    this.setData({ houseList })
    // const res = await wx.http.get('/room')
    // console.log(res);
  },
  // 删除

  goDetail(ev) {
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + ev.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
